<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Escape special characters in a string for use in an SQL statement</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.cubrid-query.html">cubrid_query</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-result.html">cubrid_result</a></div>
 <div class="up"><a href="cubridmysql.cubrid.html">CUBRID MySQL 兼容性函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.cubrid-real-escape-string" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_real_escape_string</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.0)</p><p class="refpurpose"><span class="refname">cubrid_real_escape_string</span> &mdash; <span class="dc-title">Escape special characters in a string for use in an SQL statement</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-real-escape-string-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>cubrid_real_escape_string</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$unescaped_string</code></span>
   [, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$conn_identifier</code></span>
  ] )</div>

  <p class="para rdfs-comment">
    This function returns the escaped string version of the given string. It
    will escape the following characters: <strong><code>&#039;</code></strong>. 

    In general, single quotations are used to enclose character string. Double
    quotations may be used as well depending on the value of ansi_quotes,
    which is a parameter related to SQL statement. If the ansi_quotes value is
    set to no, character string enclosed by double quotations is handled as
    character string, not as an identifier. The default value is yes.

    If you want to include a single quote as part of a character string, enter
    two single quotes in a row.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.cubrid-real-escape-string-parameters">
 <h3 class="title">参数</h3>
 <p class="para">
  <dl>

    
     <dt>
<em><code class="parameter">unescaped_string</code></em></dt>

     <dd>
<p class="para">The string that is to be escaped.</p></dd>

    
    
     <dt>
<em><code class="parameter">conn_identifier</code></em></dt>

     <dd>
<p class="para">
     The CUBRID connection. If the connection identifier is not specified, the
     last connection opened by <span class="function"><a href="function.cubrid-connect.html" class="function">cubrid_connect()</a></span> is assumed.
     </p></dd>

    
  </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-real-escape-string-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Escaped string version of the given string, on success.
  </p>
   <p class="para">
    <strong><code>FALSE</code></strong> on failure.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-real-escape-string-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1061">
   <p><strong>Example #1 <span class="function"><strong>cubrid_real_escape_string()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$unescaped_str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'&nbsp;!"#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$escaped_str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_real_escape_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$unescaped_str</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$len&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$unescaped_str</span><span style="color: #007700">);<br /><br />@</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;cubrid_test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;cubrid_test&nbsp;(t&nbsp;char(</span><span style="color: #0000BB">$len</span><span style="color: #DD0000">))"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"INSERT&nbsp;INTO&nbsp;cubrid_test&nbsp;(t)&nbsp;VALUES('</span><span style="color: #0000BB">$escaped_str</span><span style="color: #DD0000">')"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$req&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;cubrid_test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$row</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">cubrid_close_request</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(1) {
  [&quot;t&quot;]=&gt;
  string(95) &quot; !&quot;#$%&amp;&#039;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~&quot;
}
</pre></div>
    </div>
  </div>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.cubrid-query.html">cubrid_query</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-result.html">cubrid_result</a></div>
 <div class="up"><a href="cubridmysql.cubrid.html">CUBRID MySQL 兼容性函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
